/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * WidokNowaGra.java
 *
 * Created on 2010-06-24, 18:18:56
 */
package okna;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import menadzery.Klient;
import menadzery.Rozgrywka;

/**
 *
 * @author sufka
 */
public class WidokNowaGra extends javax.swing.JFrame {

    /** Creates new form WidokNowaGra */
    private Klient klient;

    public WidokNowaGra() {
        super("Poker");
        initComponents();
        jTextArea1.setEditable(false);
        jButton1.setEnabled(false);
        jTextField1.setEnabled(false);
        jTextField1.setEditable(false);
        jButton2.setEnabled(false);
        jTextField2.setEnabled(false);
        jTextField2.setEditable(false);
        jButton3.setEnabled(false);
        jTextField3.setEnabled(false);
        jTextField3.setEditable(false);
        jButton4.setEnabled(false);
    }

    public void setKlient(Klient klient) {
        this.klient = klient;
    }

    public JTextArea getJTextArea1() {
        return jTextArea1;
    }

    public JButton getJButton2() {
        return jButton2;
    }

    public JTextField getJTextField2() {
        return jTextField2;
    }

    public JTextField getJTextField3() {
        return jTextField3;
    }

    public JButton getJButton3() {
        return jButton3;
    }

    public JButton getJButton4() {
        return jButton4;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    private void initComponents() {//GEN-BEGIN:initComponents

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jTextField2 = new javax.swing.JTextField();
        jTextField3 = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jButton2 = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("Login");

        jLabel2.setText("Ile graczy");

        jLabel3.setText("Poczatkowa kasa");

        jButton1.setText("Nowa gra");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane1.setViewportView(jTextArea1);

        jButton2.setText("Potwierdz login");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setText("Potwierdz graczy");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setText("Potwierdz kase");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jLabel5.setText(":)");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 478, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addComponent(jLabel2)
                            .addComponent(jLabel1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE)
                            .addComponent(jTextField3, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE)
                            .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jButton4))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(60, 60, 60)
                                .addComponent(jButton1)))
                        .addGap(9, 9, 9))
                    .addComponent(jLabel4))
                .addGap(56, 56, 56))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel5)
                .addContainerGap(526, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton2)
                    .addComponent(jButton1))
                .addGap(27, 27, 27)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton3))
                .addGap(28, 28, 28)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 13, Short.MAX_VALUE)
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:      
       // klient.setRozgrywka(new Rozgrywka());
        klient.getOut().println("gracz");
        jButton1.setEnabled(false);
        
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        jLabel5.setText(":)");
        String war = jTextField1.getText();
        try {
            if (war.isEmpty() == true) {
                throw new NumberFormatException();
            }
        } catch (NumberFormatException blad) {
            jLabel5.setText("Brak lub zle wpisane dane!");
            return;
        }
        klient.getGracz().setLogin(war);
        klient.getOut().println(war);
        jTextField1.setEnabled(false);
        jTextField1.setEditable(false);
        jButton2.setEnabled(false);
        

    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
        jLabel5.setText(":)");
        String war = jTextField2.getText();
        try {
            if (war.isEmpty() == true) {
                throw new NumberFormatException();
            }
            Integer.getInteger(war);
        } catch (NumberFormatException blad) {
            jLabel5.setText("Brak lub zle wpisane dane!");
            return;
        }
        Integer wart = new Integer(war);
        if (wart >= 5 && wart <= 1) {
            jLabel5.setText("Musisz wpisac liczba z przedzialu (2-4)");
            return;
        } else {
            klient.getOut().println(wart);
            jTextField2.setEnabled(false);
            jTextField2.setEditable(false);
            jButton3.setEnabled(false);
        }
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        // TODO add your handling code here:
        jLabel5.setText(":)");
        String war = jTextField3.getText();
        try {
            if (war.isEmpty() == true) {
                throw new NumberFormatException();
            }
            Integer.getInteger(war);
        } catch (NumberFormatException blad) {
            jLabel5.setText("Brak lub zle wpisane dane!");
            return;
        }
        Integer wart = new Integer(war);
        if (wart >= 100001 && wart <= 99) {
            jLabel5.setText("Musisz wpisac liczba z przedzialu (100-100000)");
            return;
        } else {
            klient.getOut().println(wart);
            jTextField3.setEnabled(false);
            jTextField3.setEditable(false);
            jButton4.setEnabled(false);
        }


    }//GEN-LAST:event_jButton4ActionPerformed

    public void podajIluGraczy() {
        jTextField2.setEnabled(true);
        jTextField2.setEditable(true);
        jButton3.setEnabled(true);
        jTextArea1.append("Podaj liczbe graczy do gry w Pokera (2-4)\n");
    }

    public void podajIleKasy() {
        jTextField3.setEnabled(true);
        jTextField3.setEditable(true);
        jButton4.setEnabled(true);
        jTextArea1.append("Jaka jest pula wejsciowa (ante)? (100-100000)\n");
    }

    public void podajLogin() {
        jTextField1.setEnabled(true);
        jTextField1.setEditable(true);
        jButton2.setEnabled(true);
        jTextArea1.append("Wpisz swoj login i potwierdz.\n");
    }

    public void wczytajKaseIPokazStol(){
        jButton1.setEnabled(true);
        jTextArea1.append("Rozpocznij gre w POKERA :)\n");
        Integer iloscKasy = new Integer(0);
        try {
            iloscKasy = klient.odbierzInta();
        } catch (IOException ex) {
            Logger.getLogger(WidokNowaGra.class.getName()).log(Level.SEVERE, null, ex);
        }
        klient.getGracz().setStanKonta(iloscKasy);
        for(int i = 0; i < klient.getRozgrywka().getLiczbaGraczy();++i){
            klient.getRozgrywka().getGracze().elementAt(i).setStanKonta(iloscKasy);
        }
    }
    /**
     * @param args the command line arguments
     */
//    public static void main(String args[]) {
//        java.awt.EventQueue.invokeLater(new Runnable() {
//            public void run() {
//                new WidokNowaGra().setVisible(true);
//            }
//        });
//    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    // End of variables declaration//GEN-END:variables
}
